package cn.harry.cabinet.server.dto.config

import cn.harry.cabinet.model.entity.Configuration
import kotlinx.serialization.InternalSerializationApi
import kotlinx.serialization.Serializable

@InternalSerializationApi
@Serializable
data class ConfigurationResponse(
	val id: Long,
	val type: String,
	val key: String,
	val value: String,
	val createTime: Long,
	val updateTime: Long
) {
	companion object {
		fun from(config: Configuration): ConfigurationResponse = ConfigurationResponse(
			id = config.id,
			type = config.type,
			key = config.key,
			value = config.value,
			createTime = config.createTime.time,
			updateTime = config.updateTime.time
		)

		fun fromList(list: List<Configuration>): List<ConfigurationResponse> = list.map { from(it) }
	}
}

@InternalSerializationApi
@Serializable
data class ConfigurationCreateRequest(
	val type: String,
	val key: String,
	val value: String
) {
	fun isValid(): Boolean = type.isNotBlank() && key.isNotBlank()
}

@InternalSerializationApi
@Serializable
data class ConfigurationUpdateRequest(
	val value: String
) {
	fun isValid(): Boolean = true
}

